
package dialogs;

import core.COINCOMOSubComponent;
import database.COINCOMOComponentManager;
import database.COINCOMOSubComponentManager;
import java.awt.BorderLayout;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.text.DecimalFormat;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTabbedPane;
import javax.swing.JTextField;
import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
import main.GlobalMethods;
import main.Icons;
import panels.ComponentOverviewPanel;

/**
 *
 * @author Raed Shomali
 */
public class SubComponentSizeDialog extends JDialog implements ActionListener, ChangeListener
{
    DecimalFormat format1Decimal = new DecimalFormat( "0.0" );

    DecimalFormat format2Decimals = new DecimalFormat( "0.00" );
    // Languages
    JLabel languagesLabel = new JLabel( "Languages:" );

    String languages[] =
    {
        "Access" ,
        "Ada 83" ,
        "Ada 95" ,
        "AI Shell" ,
        "ANSI Basic" ,
        "ANSI COBOL 85" ,
        "APL" ,
        "Basic Assembly" ,
        "C" ,
        "C++" ,
        "Compiled Basic" ,
        "Database Default" ,
        "1st Generation" ,
        "2nd Generation" ,
        "3rd Generation" ,
        "4th Generation" ,
        "5th Generation" ,
        "Forth" ,
        "FORTRAN 77" ,
        "FORTRAN 95" ,
        "High Level" ,
        "HTML 3.0" ,
        "Interpreted Basic" ,
        "Java" ,
        "Lisp" ,
        "Machine Code" ,
        "Microassembly" ,
        "Modula 2" ,
        "N/A" ,
        "Object Oriented Default" ,
        "Pascal" ,
        "Perl" ,
        "Power Builder" ,
        "Procedural Language" ,
        "PROLOG" ,
        "Query Default" ,
        "Report Generator" ,
        "Simulation Default" ,
        "Spreadsheet Default" ,
        "Unknown Language" ,
        "Unix Shell Script" ,
        "USR 1" ,
        "USR 2" ,
        "USR 3" ,
        "USR 4" ,
        "USR 5" ,
        "Visual Basic 5" ,
        "Visual C++"
    };

    JLabel sizingTypeLabel = new JLabel( "Select a sizing type:" ) ;
    
    JComboBox languagesComboBox = new JComboBox( languages );
    // Breakage
    JLabel breakageLabel = new JLabel( "" );

    JLabel breakageDescLabel = new JLabel( "<html><body>% of Code thrown away due to requirements evolution and volitality</body></html>" );

    JLabel breakageREVLLabel = new JLabel( "REVL:" );

    JTextField breakageTextField = new JTextField( "0" );
    // Sloc
    JLabel SLOCLabel = new JLabel( "SLOC:" );

    JTextField SLOCTextField = new JTextField( "0" );

    // Function Points
    JLabel functionTypeLabel = new JLabel( "Function Type" );

    JLabel subTotalLabel = new JLabel( "Sub Total" );

    JLabel inputLabel = new JLabel( "Inputs:" );

    JLabel inputResultsLabel = new JLabel( "?" );

    JLabel outputLabel = new JLabel( "Outputs:" );

    JLabel outputResultsLabel = new JLabel( "?" );

    JLabel fileLabel = new JLabel( "Files:" );

    JLabel fileResultsLabel = new JLabel( "?" );

    JLabel interfaceLabel = new JLabel( "Interfaces:" );

    JLabel interfaceResultsLabel = new JLabel( "?" );

    JLabel queryLabel = new JLabel( "Queries:" );

    JLabel queryResultsLabel = new JLabel( "?" );

    JLabel totalLabel = new JLabel( "Total Unadjusted Function Points:" );

    JLabel eSLOCLabel = new JLabel( "Equivalent SLOC:" );

    JLabel eSLOCResultsLabel = new JLabel( "?" );

    JTextField functionTextField[] = new JTextField[ 15 ];

    JTextField totalTextField = new JTextField();
    // Adaptation and Reuse
    
    JTextField initialSLOCTextField = new JTextField() ;
    
    JLabel label0 = new JLabel( "Initial SLOC:" ) ;
    
    JLabel label1 = new JLabel( "% Design Modified (DM):" );

    JLabel label2 = new JLabel( "% Code Modified (CM):" );

    JLabel label3 = new JLabel( "% Integration Modified (IM):" );

    JLabel label4 = new JLabel( "Software Understanding (SU):" );

    JLabel label5 = new JLabel( "Assessment & Assimilation:" );

    JLabel label6 = new JLabel( "Unfamiliarity With Software:" );

    JLabel label7 = new JLabel( "Components Automatically Translated:" );

    JLabel label8 = new JLabel( "Automatic Translation Productivity Level:" );

    JLabel label9 = new JLabel( "Computed Adaptation Adjustment Factor:" );

    JLabel label10 = new JLabel( "Computed ASLOC:" );

    JLabel label11 = new JLabel( "%" );

    JLabel label12 = new JLabel( "%" );

    JLabel label13 = new JLabel( "%" );

    JLabel label14 = new JLabel( "SU (0 - 50%)" );

    JLabel label15 = new JLabel( "AA (0 - 8%)" );

    JLabel label16 = new JLabel( "UNFM (0 - 1)" );

    JLabel label17 = new JLabel( "%" );

    JLabel label18 = new JLabel( "" );

    JLabel adjustmentFactorLabel = new JLabel( "?" );

    JLabel ASLOCValueLabel = new JLabel( "?" );

    JTextField adaptationReuseTextField[] = new JTextField[ 8 ];
    // Tabs
    JTabbedPane tabs = new JTabbedPane();
    // Buttons
    JButton applyButton = new JButton( "Apply" );

    JButton closeButton = new JButton( "Close" );

    COINCOMOSubComponent subComponent = null;

    int rowNumber = 0;

    public SubComponentSizeDialog( JFrame owner , COINCOMOSubComponent subComponent , int rowNumber )
    {
        super( owner );

        this.setModal( true );

        this.setTitle( "Size - " + subComponent.getName() );
        
        this.rowNumber = rowNumber;
        this.subComponent = subComponent;

        GlobalMethods.updateStatusBar( "Done." );

        // Labels
        SLOCLabel.setFont( new Font( "arial" , 1 , 11 ) );
        languagesLabel.setFont( new Font( "arial" , 1 , 11 ) );
        breakageLabel.setFont( new Font( "arial" , 1 , 11 ) );
        breakageDescLabel.setFont( new Font( "arial" , 1 , 11 ) );
        breakageREVLLabel.setFont( new Font( "arial" , 1 , 11 ) );

        TitledBorder legendTitleBorder = BorderFactory.createTitledBorder( "Breakage" );
        legendTitleBorder.setTitleColor( Color.BLUE );
        breakageLabel.setBorder( legendTitleBorder );

        // ComboBox
        languagesComboBox.setBackground( Color.WHITE );
        languagesComboBox.setFont( new Font( "arial" , 1 , 12 ) );

        // Buttons
        applyButton.addActionListener( this );
        closeButton.addActionListener( this );

        applyButton.setFocusable( false );
        closeButton.setFocusable( false );

        applyButton.setIcon( Icons.SAVE_ICON );
        closeButton.setIcon( Icons.CLOSE_ICON );

        // Panel Tabs
        JPanel slocPanel = new JPanel( null );
        slocPanel.add( SLOCLabel );
        slocPanel.add( SLOCTextField );

        SLOCLabel.setBounds( 20 , 20 , 50 , 20 );
        SLOCTextField.setBounds( 70 , 20 , 100 , 20 );


        functionTypeLabel.setFont( new Font( "arial" , 1 , 11 ) );
        subTotalLabel.setFont( new Font( "arial" , 1 , 11 ) );
        inputLabel.setFont( new Font( "arial" , 1 , 11 ) );
        inputResultsLabel.setFont( new Font( "arial" , 1 , 11 ) );
        outputLabel.setFont( new Font( "arial" , 1 , 11 ) );
        outputResultsLabel.setFont( new Font( "arial" , 1 , 11 ) );
        fileLabel.setFont( new Font( "arial" , 1 , 11 ) );
        fileResultsLabel.setFont( new Font( "arial" , 1 , 11 ) );
        interfaceLabel.setFont( new Font( "arial" , 1 , 11 ) );
        interfaceResultsLabel.setFont( new Font( "arial" , 1 , 11 ) );
        queryLabel.setFont( new Font( "arial" , 1 , 11 ) );
        queryResultsLabel.setFont( new Font( "arial" , 1 , 11 ) );
        totalLabel.setFont( new Font( "arial" , 1 , 11 ) );
        eSLOCLabel.setFont( new Font( "arial" , 1 , 11 ) );
        eSLOCResultsLabel.setFont( new Font( "arial" , 1 , 11 ) );

        functionTypeLabel.setHorizontalAlignment( JLabel.CENTER );
        inputLabel.setHorizontalAlignment( JLabel.CENTER );
        inputResultsLabel.setHorizontalAlignment( JLabel.CENTER );
        outputLabel.setHorizontalAlignment( JLabel.CENTER );
        outputResultsLabel.setHorizontalAlignment( JLabel.CENTER );
        fileLabel.setHorizontalAlignment( JLabel.CENTER );
        fileResultsLabel.setHorizontalAlignment( JLabel.CENTER );
        interfaceLabel.setHorizontalAlignment( JLabel.CENTER );
        interfaceResultsLabel.setHorizontalAlignment( JLabel.CENTER );
        queryLabel.setHorizontalAlignment( JLabel.CENTER );
        queryResultsLabel.setHorizontalAlignment( JLabel.CENTER );
        eSLOCResultsLabel.setHorizontalAlignment( JLabel.CENTER );

        functionTypeLabel.setForeground( Color.BLUE );
        subTotalLabel.setForeground( Color.BLUE );

        JPanel functionPointsPanel = new JPanel( null );
        functionPointsPanel.add( functionTypeLabel );
        functionPointsPanel.add( subTotalLabel );
        functionPointsPanel.add( inputLabel );
        functionPointsPanel.add( inputResultsLabel );
        functionPointsPanel.add( outputLabel );
        functionPointsPanel.add( outputResultsLabel );
        functionPointsPanel.add( fileLabel );
        functionPointsPanel.add( fileResultsLabel );
        functionPointsPanel.add( interfaceLabel );
        functionPointsPanel.add( interfaceResultsLabel );
        functionPointsPanel.add( queryLabel );
        functionPointsPanel.add( queryResultsLabel );
        functionPointsPanel.add( totalLabel );
        functionPointsPanel.add( eSLOCLabel );
        functionPointsPanel.add( eSLOCResultsLabel );

        functionPointsPanel.add( totalTextField );

        functionTypeLabel.setBounds( 30 , 20 , 100 , 20 );
        subTotalLabel.setBounds( 300 , 20 , 100 , 20 );

        inputLabel.setBounds( 30 , 40 , 100 , 20 );
        inputResultsLabel.setBounds( 300 , 40 , 50 , 20 );

        outputLabel.setBounds( 30 , 60 , 100 , 20 );
        outputResultsLabel.setBounds( 300 , 60 , 50 , 20 );

        fileLabel.setBounds( 30 , 80 , 100 , 20 );
        fileResultsLabel.setBounds( 300 , 80 , 50 , 20 );

        interfaceLabel.setBounds( 30 , 100 , 100 , 20 );
        interfaceResultsLabel.setBounds( 300 , 100 , 50 , 20 );

        queryLabel.setBounds( 30 , 120 , 100 , 20 );
        queryResultsLabel.setBounds( 300 , 120 , 50 , 20 );

        totalLabel.setBounds( 60 , 170 , 200 , 20 );
        totalTextField.setBounds( 280 , 170 , 80 , 20 );

        eSLOCLabel.setBounds( 60 , 190 , 100 , 20 );
        eSLOCResultsLabel.setBounds( 280 , 190 , 80 , 20 );

        functionTextField[ 0] = new JTextField();
        functionTextField[ 1] = new JTextField();
        functionTextField[ 2] = new JTextField();
        functionTextField[ 3] = new JTextField();
        functionTextField[ 4] = new JTextField();
        functionTextField[ 5] = new JTextField();
        functionTextField[ 6] = new JTextField();
        functionTextField[ 7] = new JTextField();
        functionTextField[ 8] = new JTextField();
        functionTextField[ 9] = new JTextField();
        functionTextField[ 10] = new JTextField();
        functionTextField[ 11] = new JTextField();
        functionTextField[ 12] = new JTextField();
        functionTextField[ 13] = new JTextField();
        functionTextField[ 14] = new JTextField();

        functionTextField[ 0].setBounds( 135 , 40 , 50 , 20 );
        functionTextField[ 1].setBounds( 185 , 40 , 50 , 20 );
        functionTextField[ 2].setBounds( 235 , 40 , 50 , 20 );
        functionTextField[ 3].setBounds( 135 , 60 , 50 , 20 );
        functionTextField[ 4].setBounds( 185 , 60 , 50 , 20 );
        functionTextField[ 5].setBounds( 235 , 60 , 50 , 20 );
        functionTextField[ 6].setBounds( 135 , 80 , 50 , 20 );
        functionTextField[ 7].setBounds( 185 , 80 , 50 , 20 );
        functionTextField[ 8].setBounds( 235 , 80 , 50 , 20 );
        functionTextField[ 9].setBounds( 135 , 100 , 50 , 20 );
        functionTextField[ 10].setBounds( 185 , 100 , 50 , 20 );
        functionTextField[ 11].setBounds( 235 , 100 , 50 , 20 );
        functionTextField[ 12].setBounds( 135 , 120 , 50 , 20 );
        functionTextField[ 13].setBounds( 185 , 120 , 50 , 20 );
        functionTextField[ 14].setBounds( 235 , 120 , 50 , 20 );

        functionPointsPanel.add( functionTextField[ 0] );
        functionPointsPanel.add( functionTextField[ 1] );
        functionPointsPanel.add( functionTextField[ 2] );
        functionPointsPanel.add( functionTextField[ 3] );
        functionPointsPanel.add( functionTextField[ 4] );
        functionPointsPanel.add( functionTextField[ 5] );
        functionPointsPanel.add( functionTextField[ 6] );
        functionPointsPanel.add( functionTextField[ 7] );
        functionPointsPanel.add( functionTextField[ 8] );
        functionPointsPanel.add( functionTextField[ 9] );
        functionPointsPanel.add( functionTextField[ 10] );
        functionPointsPanel.add( functionTextField[ 11] );
        functionPointsPanel.add( functionTextField[ 12] );
        functionPointsPanel.add( functionTextField[ 13] );
        functionPointsPanel.add( functionTextField[ 14] );


        JPanel adaptationPanel = new JPanel( null );
        adaptationPanel.add( label0 );
        adaptationPanel.add( label1 );
        adaptationPanel.add( label2 );
        adaptationPanel.add( label3 );
        adaptationPanel.add( label4 );
        adaptationPanel.add( label5 );
        adaptationPanel.add( label6 );
        adaptationPanel.add( label7 );
        adaptationPanel.add( label8 );
        adaptationPanel.add( label9 );
        adaptationPanel.add( label10 );

        adaptationPanel.add( label11 );
        adaptationPanel.add( label12 );
        adaptationPanel.add( label13 );
        adaptationPanel.add( label14 );
        adaptationPanel.add( label15 );
        adaptationPanel.add( label16 );
        adaptationPanel.add( label17 );
        adaptationPanel.add( label18 );
        adaptationPanel.add( adjustmentFactorLabel  );
        adaptationPanel.add( ASLOCValueLabel    );
        
        adaptationPanel.add( initialSLOCTextField  );

        label0.setFont( new Font( "arial" , 1 , 11 ) );
        label1.setFont( new Font( "arial" , 1 , 11 ) );
        label2.setFont( new Font( "arial" , 1 , 11 ) );
        label3.setFont( new Font( "arial" , 1 , 11 ) );
        label4.setFont( new Font( "arial" , 1 , 11 ) );
        label5.setFont( new Font( "arial" , 1 , 11 ) );
        label6.setFont( new Font( "arial" , 1 , 11 ) );
        label7.setFont( new Font( "arial" , 1 , 11 ) );
        label8.setFont( new Font( "arial" , 1 , 11 ) );
        label9.setFont( new Font( "arial" , 1 , 11 ) );
        label10.setFont( new Font( "arial" , 1 , 11 ) );

        label11.setFont( new Font( "arial" , 1 , 11 ) );
        label12.setFont( new Font( "arial" , 1 , 11 ) );
        label13.setFont( new Font( "arial" , 1 , 11 ) );
        label14.setFont( new Font( "arial" , 1 , 11 ) );
        label15.setFont( new Font( "arial" , 1 , 11 ) );
        label16.setFont( new Font( "arial" , 1 , 11 ) );
        label17.setFont( new Font( "arial" , 1 , 11 ) );
        label18.setFont( new Font( "arial" , 1 , 11 ) );
        adjustmentFactorLabel.setFont( new Font( "arial" , 1 , 11 ) );
        ASLOCValueLabel.setFont( new Font( "arial" , 1 , 11 ) );
        
        sizingTypeLabel.setFont( new Font( "arial" , 1 , 11 ) );

        label0.setBounds( 40 , 20 , 300 , 20 );
        label1.setBounds( 40 , 40 , 300 , 20 );
        label2.setBounds( 40 , 60 , 300 , 20 );
        label3.setBounds( 40 , 80 , 300 , 20 );
        label4.setBounds( 40 , 100 , 300 , 20 );
        label5.setBounds( 40 , 120 , 300 , 20 );
        label6.setBounds( 40 , 140 , 300 , 20 );
        label7.setBounds( 40 , 160 , 300 , 20 );
        label8.setBounds( 40 , 180 , 300 , 20 );
        label9.setBounds( 40 , 210 , 300 , 20 );
        label10.setBounds( 40 , 230 , 300 , 20 );

        label11.setBounds( 340 , 40 , 50 , 20 );
        label12.setBounds( 340 , 60 , 50 , 20 );
        label13.setBounds( 340 , 80 , 50 , 20 );
        label14.setBounds( 340 , 100 , 150 , 20 );
        label15.setBounds( 340 , 120 , 150 , 20 );
        label16.setBounds( 340 , 140 , 150 , 20 );
        label17.setBounds( 340 , 160 , 50 , 20 );
        label18.setBounds( 340 , 180 , 50 , 20 );
        adjustmentFactorLabel.setBounds( 340 , 210 , 50 , 20 );
        ASLOCValueLabel.setBounds( 340 , 230 , 50 , 20 );

        initialSLOCTextField.setBounds( 280 , 20 , 50 , 20 );
        
        for ( int i = 0 ; i < adaptationReuseTextField.length ; i++ )
        {
            adaptationReuseTextField[i] = new JTextField();

            adaptationPanel.add( adaptationReuseTextField[i] );

            adaptationReuseTextField[i].setBounds( 280 , 40 + 20 * i , 50 , 20 );
        }

        // Tabs
        tabs.addTab( "New" , slocPanel );
        tabs.addTab( "Function Points" , functionPointsPanel );
        tabs.addTab( "Adaptation & Reuse" , adaptationPanel );

        tabs.addChangeListener( this ) ;
        
        // GUI
        JPanel northPanel = new JPanel( null );
        northPanel.add( languagesLabel );
        northPanel.add( languagesComboBox );
        northPanel.add( breakageLabel );
        northPanel.add( breakageDescLabel );
        northPanel.add( breakageREVLLabel );
        northPanel.add( breakageTextField );
        northPanel.add( sizingTypeLabel ) ;

        northPanel.setPreferredSize( new Dimension( 100 , 120 ) );

        languagesLabel.setBounds( 15 , 10 , 170 , 20 );
        languagesComboBox.setBounds( 15 , 35 , 170 , 20 );
        breakageLabel.setBounds( 230 , 10 , 230 , 100 );
        breakageDescLabel.setBounds( 245 , 30 , 220 , 40 );
        breakageREVLLabel.setBounds( 245 , 75 , 50 , 20 );
        breakageTextField.setBounds( 295 , 75 , 150 , 20 );
        sizingTypeLabel.setBounds( 15 , 95 , 170 , 20 );

        JPanel southPanel = new JPanel();
        southPanel.add( applyButton );
        southPanel.add( closeButton );

        this.setLayout( new BorderLayout() );
        this.add( northPanel , BorderLayout.NORTH );
        this.add( tabs );
        this.add( southPanel , BorderLayout.SOUTH );

        // Loading ...
        loadParameters();

        this.setDefaultCloseOperation( JDialog.DISPOSE_ON_CLOSE );
        this.setLocation( this.getOwner().getX() + 100 , this.getOwner().getY() + 100 );
        this.setResizable( false );
        this.setSize( 480 , 480 );
        this.setVisible( true );
    }

    /**
     * 
     */
    public void loadParameters()
    {
        tabs.setSelectedIndex( subComponent.getSizingType() ) ;
        
        applyButton.setEnabled( false );
        closeButton.setEnabled( false );

        SLOCTextField.setText( subComponent.getSLOC() + "" );

        languagesComboBox.setSelectedItem( subComponent.getLanguage() );

        breakageTextField.setText( subComponent.getBreakage() + "" );
        
        functionTextField[ 0 ].setText( subComponent.getExternalInputs()[ 0 ] + "" );
        functionTextField[ 1 ].setText( subComponent.getExternalInputs()[ 1 ] + "" );
        functionTextField[ 2 ].setText( subComponent.getExternalInputs()[ 2 ] + "" );
        functionTextField[ 3 ].setText( subComponent.getExternalOutputs()[ 0 ] + "" );
        functionTextField[ 4 ].setText( subComponent.getExternalOutputs()[ 1 ] + "" );
        functionTextField[ 5 ].setText( subComponent.getExternalOutputs()[ 2 ] + "" );
        functionTextField[ 6 ].setText( subComponent.getInternalLogicalFiles()[ 0 ] + "" );
        functionTextField[ 7 ].setText( subComponent.getInternalLogicalFiles()[ 1 ] + "" );
        functionTextField[ 8 ].setText( subComponent.getInternalLogicalFiles()[ 2 ] + "" );
        functionTextField[ 9 ].setText( subComponent.getExternalInterfaceFiles()[ 0 ] + "" );
        functionTextField[ 10 ].setText( subComponent.getExternalInterfaceFiles()[ 1 ] + "" );
        functionTextField[ 11 ].setText( subComponent.getExternalInterfaceFiles()[ 2 ] + "" );
        functionTextField[ 12 ].setText( subComponent.getExternalInquiries()[ 0 ] + "" );
        functionTextField[ 13 ].setText( subComponent.getExternalInquiries()[ 1 ] + "" );
        functionTextField[ 14 ].setText( subComponent.getExternalInquiries()[ 2 ] + "" );

        initialSLOCTextField.setText( subComponent.getInitialSLOC() + "" ) ;
        
        adaptationReuseTextField[ 0 ].setText( subComponent.getDesignModified() + "" );
        adaptationReuseTextField[ 1 ].setText( subComponent.getCodeModified() + "" );
        adaptationReuseTextField[ 2 ].setText( subComponent.getIntegrationModified() + "" );
        adaptationReuseTextField[ 3 ].setText( subComponent.getSoftwareUnderstanding() + "" );
        adaptationReuseTextField[ 4 ].setText( subComponent.getAssementAssimilation() + "" );
        adaptationReuseTextField[ 5 ].setText( subComponent.getUnfamiliarity() + "" );
        adaptationReuseTextField[ 6 ].setText( subComponent.getAutomaticallyTranslated() + "" );
        adaptationReuseTextField[ 7 ].setText( subComponent.getAutoTranslationProductivity() + "" );
        
        adjustmentFactorLabel.setText( subComponent.getAdaptationAdjustmentFactor() + "" ) ;
        ASLOCValueLabel.setText( subComponent.getAdaptiveSLOC() + "" ) ;
        
        // Set Back To Default ...
        applyButton.setEnabled( true );
        closeButton.setEnabled( true );

        GlobalMethods.updateStatusBar( "Parameters Loaded." );
    }

    public void actionPerformed( ActionEvent e )
    {
        if ( e.getSource() == applyButton )
        {
            // Validations
            if ( !GlobalMethods.isNonNegativeLong( SLOCTextField.getText() ) )
            {
                GlobalMethods.updateStatusBar( "SLOC Must be a Non Negative Integer Value." , Color.RED );

                return;
            }

            if ( !GlobalMethods.isNonNegativeLong( initialSLOCTextField.getText() ) )
            {
                GlobalMethods.updateStatusBar( "Initial SLOC Must be a Non Negative Integer Value." , Color.RED );

                return;
            }

            if ( !GlobalMethods.isNonNegativeFloat( breakageTextField.getText() ) )
            {
                GlobalMethods.updateStatusBar( "Breakage Must be a Non Negative Float Value." , Color.RED );

                return;
            }

            // Function Points
            for( int i = 0 ; i < functionTextField.length ; i ++ )
            {
                if( !GlobalMethods.isNonNegativeLong( functionTextField[ i ].getText() ) )
                {
                    GlobalMethods.updateStatusBar( "All Function Points Must be Non-Negative Integers" , Color.RED );

                    return;
                }
            }
            
            if( Long.parseLong( functionTextField[ 0 ].getText() ) > Long.parseLong( functionTextField[ 1 ].getText() ) 
                    || Long.parseLong( functionTextField[ 1 ].getText() ) > Long.parseLong( functionTextField[ 2 ].getText() ) )
            {
                GlobalMethods.updateStatusBar( "Input Function Point Average Must be between its Boundaries." , Color.RED );

                return;
            }
            
            if( Long.parseLong( functionTextField[ 3 ].getText() ) > Long.parseLong( functionTextField[ 4 ].getText() ) 
                    || Long.parseLong( functionTextField[ 4 ].getText() ) > Long.parseLong( functionTextField[ 5 ].getText() ) )
            {
                GlobalMethods.updateStatusBar( "Output Function Point Average Must be between its Boundaries." , Color.RED );

                return;
            }
            
            if( Long.parseLong( functionTextField[ 6 ].getText() ) > Long.parseLong( functionTextField[ 7 ].getText() ) 
                    || Long.parseLong( functionTextField[ 7 ].getText() ) > Long.parseLong( functionTextField[ 8 ].getText() ) )
            {
                GlobalMethods.updateStatusBar( "File Function Point Average Must be between its Boundaries." , Color.RED );

                return;
            }
            
            if( Long.parseLong( functionTextField[ 9 ].getText() ) > Long.parseLong( functionTextField[ 10 ].getText() ) 
                    || Long.parseLong( functionTextField[ 10 ].getText() ) > Long.parseLong( functionTextField[ 11 ].getText() ) )
            {
                GlobalMethods.updateStatusBar( "Interface Function Point Average Must be between its Boundaries." , Color.RED );

                return;
            }
            
            if( Long.parseLong( functionTextField[ 12 ].getText() ) > Long.parseLong( functionTextField[ 13 ].getText() ) 
                    || Long.parseLong( functionTextField[ 13 ].getText() ) > Long.parseLong( functionTextField[ 14 ].getText() ) )
            {
                GlobalMethods.updateStatusBar( "Query Function Point Average Must be between its Boundaries." , Color.RED );

                return;
            }
            
            // Adaptation and Reuse
            if ( !GlobalMethods.isNonNegativeFloat( adaptationReuseTextField[ 0].getText() ) && Float.parseFloat( adaptationReuseTextField[ 0].getText() ) >= 0 && Float.parseFloat( adaptationReuseTextField[ 0].getText() ) <= 100 )
            {
                GlobalMethods.updateStatusBar( "Design Modified Must be a value between 0 and 100" , Color.RED );

                return;
            }

            if ( !GlobalMethods.isNonNegativeFloat( adaptationReuseTextField[ 1].getText() ) && Float.parseFloat( adaptationReuseTextField[ 1].getText() ) >= 0 && Float.parseFloat( adaptationReuseTextField[ 1].getText() ) <= 100 )
            {
                GlobalMethods.updateStatusBar( "Code Modified Must be a value between 0 and 100" , Color.RED );

                return;
            }

            if ( !GlobalMethods.isNonNegativeFloat( adaptationReuseTextField[ 2].getText() ) && Float.parseFloat( adaptationReuseTextField[ 2].getText() ) >= 0 && Float.parseFloat( adaptationReuseTextField[ 2].getText() ) <= 100 )
            {
                GlobalMethods.updateStatusBar( "Integration Modified Must be a value between 0 and 100" , Color.RED );

                return;
            }

            if ( !GlobalMethods.isNonNegativeFloat( adaptationReuseTextField[ 3].getText() ) && Float.parseFloat( adaptationReuseTextField[ 3].getText() ) >= 0 && Float.parseFloat( adaptationReuseTextField[ 3].getText() ) <= 50 )
            {
                GlobalMethods.updateStatusBar( "Software Understanding Must be a value between 0 and 50" , Color.RED );

                return;
            }

            if ( !GlobalMethods.isNonNegativeFloat( adaptationReuseTextField[ 4].getText() ) && Float.parseFloat( adaptationReuseTextField[ 4].getText() ) >= 0 && Float.parseFloat( adaptationReuseTextField[ 4].getText() ) <= 8 )
            {
                GlobalMethods.updateStatusBar( "Assement & Assimilation Must be a value between 0 and 8" , Color.RED );

                return;
            }

            if ( !GlobalMethods.isNonNegativeFloat( adaptationReuseTextField[ 5].getText() ) && Float.parseFloat( adaptationReuseTextField[ 5].getText() ) >= 0 && Float.parseFloat( adaptationReuseTextField[ 5].getText() ) <= 1 )
            {
                GlobalMethods.updateStatusBar( "Unfamiliarity Must be a value between 0 and 1" , Color.RED );

                return;
            }

            if ( !GlobalMethods.isNonNegativeFloat( adaptationReuseTextField[ 6].getText() ) && Float.parseFloat( adaptationReuseTextField[ 6].getText() ) >= 0 && Float.parseFloat( adaptationReuseTextField[ 6].getText() ) <= 100 )
            {
                GlobalMethods.updateStatusBar( "Automaticall Translated Components Must be a value between 0 and 100" , Color.RED );

                return;
            }


            applyButton.setEnabled( false );
            closeButton.setEnabled( false );

            GlobalMethods.updateStatusBar( "Saving ..." );

            ComponentOverviewPanel.estimationTextPane.setText( "Loading ..." );

            SwingUtilities.invokeLater( new Runnable()
            {
                public void run()
                {
                    subComponent.setSLOC( Long.parseLong( SLOCTextField.getText() ) );

                    subComponent.setLanguage( languagesComboBox.getSelectedItem().toString() );

                    subComponent.setBreakage( Float.parseFloat( breakageTextField.getText() ) );

                    // Function Points
                    subComponent.setExternalInputs( new long[]{ Long.parseLong( functionTextField[0].getText() ) , Long.parseLong( functionTextField[1].getText() ) , Long.parseLong( functionTextField[2].getText() ) } ) ;
                    subComponent.setExternalOutputs( new long[]{ Long.parseLong( functionTextField[3].getText() ) , Long.parseLong( functionTextField[4].getText() ) , Long.parseLong( functionTextField[5].getText() )  } ) ;
                    subComponent.setInternalLogicalFiles( new long[]{ Long.parseLong( functionTextField[6].getText() ) , Long.parseLong( functionTextField[7].getText() ) , Long.parseLong( functionTextField[8].getText() )  } ) ;
                    subComponent.setExternalInterfaceFiles( new long[]{ Long.parseLong( functionTextField[9].getText() ) , Long.parseLong( functionTextField[10].getText() ) , Long.parseLong( functionTextField[11].getText() )  } ) ;
                    subComponent.setExternalInquiries( new long[]{ Long.parseLong( functionTextField[12].getText() ) , Long.parseLong( functionTextField[13].getText() ) , Long.parseLong( functionTextField[14].getText() ) } ) ;
                    
                    // Adaptation & Reuse
                    subComponent.setInitialSLOC( Long.parseLong( initialSLOCTextField.getText() ) ) ;
                    
                    subComponent.setDesignModified( Float.parseFloat( adaptationReuseTextField[ 0].getText() ) );
                    subComponent.setCodeModified( Float.parseFloat( adaptationReuseTextField[ 1].getText() ) );
                    subComponent.setIntegrationModified( Float.parseFloat( adaptationReuseTextField[ 2].getText() ) );

                    subComponent.setSoftwareUnderstanding( Float.parseFloat( adaptationReuseTextField[ 3].getText() ) );
                    subComponent.setAssementAssimilation( Float.parseFloat( adaptationReuseTextField[ 4].getText() ) );
                    subComponent.setUnfamiliarity( Float.parseFloat( adaptationReuseTextField[ 5].getText() ) );
                    subComponent.setAutomaticallyTranslated( Float.parseFloat( adaptationReuseTextField[ 6].getText() ) );
                    subComponent.setAutoTranslationProductivity( Float.parseFloat( adaptationReuseTextField[ 7].getText() ) );


                    // Update Database ...
                    COINCOMOSubComponentManager.updateSubComponent( subComponent );
                    COINCOMOComponentManager.updateComponent( ComponentOverviewPanel.component );


                    // Update Table ...
                    ComponentOverviewPanel.clefTable.setValueAt( subComponent.getFinalSLOC() , rowNumber , 2 );
                    ComponentOverviewPanel.clefTable.setValueAt( subComponent.getLanguage() , rowNumber , 5 );
                    ComponentOverviewPanel.clefTable.setValueAt( format2Decimals.format( GlobalMethods.roundOff( subComponent.getEaf() , 2 ) ) , rowNumber , 4 );
                    ComponentOverviewPanel.clefTable.setValueAt( format2Decimals.format( GlobalMethods.roundOff( subComponent.getNomEffort() , 2 ) ) , rowNumber , 6 );
                    ComponentOverviewPanel.clefTable.setValueAt( format2Decimals.format( GlobalMethods.roundOff( subComponent.getEstEffort() , 2 ) ) , rowNumber , 7 );
                    ComponentOverviewPanel.clefTable.setValueAt( format2Decimals.format( GlobalMethods.roundOff( subComponent.getProd() , 2 ) ) , rowNumber , 8 );
                    ComponentOverviewPanel.clefTable.setValueAt( format2Decimals.format( GlobalMethods.roundOff( subComponent.getCost() , 2 ) ) , rowNumber , 9 );
                    ComponentOverviewPanel.clefTable.setValueAt( format2Decimals.format( GlobalMethods.roundOff( subComponent.getInstCost() , 2 ) ) , rowNumber , 10 );
                    ComponentOverviewPanel.clefTable.setValueAt( format1Decimal.format( GlobalMethods.roundOff( subComponent.getStaff() , 1 ) ) , rowNumber , 11 );


                    ASLOCValueLabel.setText( subComponent.getAdaptiveSLOC() + "" ) ;
                    adjustmentFactorLabel.setText( subComponent.getAdaptationAdjustmentFactor() + "" ) ;
                    
                    // Update Summary Report
                    ComponentOverviewPanel.updateEstimationTextPane( false );

                    // Set Back To Default ...
                    applyButton.setEnabled( true );
                    closeButton.setEnabled( true );

                    GlobalMethods.updateStatusBar( "Sub Component Saved." );
                }

            } );
        }
        else
        {
            // Free Resources ... Close Window
            this.dispose();
        }
    }

    public void stateChanged( ChangeEvent e )
    {
        JTabbedPane pane = (JTabbedPane)e.getSource();
    
        subComponent.setSizingType( pane.getSelectedIndex() );
    }
}
